package org.example.heap;

import java.util.ArrayList;
import java.util.Random;

/**
 * 测试堆溢出
 * @author youshang
 * @date 2022/03/22 09:02
 **/
public class HeapOOMTest {

    public static void main(String[] args) {
        ArrayList<Provider> providerArrayList = new ArrayList<>();

        while (true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Provider provider = new Provider();
            provider.setBytes(new byte[new Random().nextInt(1024 * 200)]);
            providerArrayList.add(provider);
        }

    }

    static class Provider {
        private byte[] bytes;

        public byte[] getBytes() {
            return bytes;
        }

        public void setBytes(byte[] bytes) {
            this.bytes = bytes;
        }
    }

}
